package cn.nubia.admin.application.controller;

import cn.nubia.admin.application.bean.Claim;
import cn.nubia.admin.application.bean.ClaimVO;
import cn.nubia.admin.application.query.ClaimQuery;
import cn.nubia.admin.application.service.ClaimService;
import cn.nubia.admin.common.mybatis.bean.Paged;
import cn.nubia.admin.sysconfig.bean.DictField;
import cn.nubia.admin.sysconfig.service.DictFieldItemService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * Created by justin on 15/7/12.
 */
@Controller
@RequestMapping(value = "/admin/claim/")
public class ClaimController {

    @Autowired
    ClaimService claimService;
    @Autowired
    DictFieldItemService dictFieldItemService;

    @RequiresPermissions(value = "soft:claim:list")
    @RequestMapping(value = "list")
     public ModelAndView list(ClaimQuery query){
        ModelAndView modelAndView = new ModelAndView("/claim/claimList");
        Paged<ClaimVO> claims = claimService.listClaims(query);
        modelAndView.addObject("claims",claims);
        modelAndView.addObject("query",query);
        modelAndView.addObject("claimTypes", dictFieldItemService.listItemsByDictName(DictField.DICTFIELDITEM_CLAIM));
        modelAndView.addObject("resTypes",Claim.resTypeMap);
        return modelAndView;
    }

    @RequestMapping(value = "view")
    public ModelAndView view(Integer id){
        ModelAndView modelAndView = new ModelAndView("/claim/claimForm");
        ClaimVO claimVO = claimService.getVOById(id);
        modelAndView.addObject("claim",claimVO);
        return modelAndView;
    }

    @RequestMapping(value = "readed")
    public String readed(Integer id){
        claimService.changeState(id, Claim.STATE_READED);
        return "redirect:list.html";
    }


    @RequestMapping(value = "delete")
    public String delete(Integer id){
        claimService.changeState(id, Claim.STATE_DEL);
        return "redirect:list.html";
    }

    @RequestMapping(value = "hidden")
    public String hidden(Integer id){
        claimService.changeState(id, Claim.STATE_HIDDEN);
        return "redirect:list.html";
    }


}
